 clear
 capture log close
 set mem 400m 
 set more off
 cd C:\个人文件\研究\1.官员家乡偏袒与省级贸易\WorkingData
 global root="C:\个人文件\研究\1.官员家乡偏袒与省级贸易"
 log using practice.log, replace
 
//图3：绘制有无关系贸易量对比图
 use  WorkingData.dta ,clear
bysort year connected_mayor: egen total_guanxi=mean(lntotal)
twoway  (connected total_guanxi  year if connected_mayor==1) (connected total_guanxi year if connected_mayor==0), scheme(s2mono) graphregion(color(white)) xtitle("Year") legend(label(1 "With connection") label(2 "Without connection")) ytitle("lntotal") xlabel(2001(2)2017) 
 //-----------1、基准回归结果-------------------------
 use WorkingData.dta, clear
 
 constraint 1 lngdp1 = lngdp2
 constraint 2 lntrade1 = lntrade2
 constraint 3 guoqibizhong1 = guoqibizhong2
 constraint 4 urban1 = urban2
 

 reg lntotal connected_mayor beijing-xinjiang i.year ,   r
 est store m1
  reg lntotal connected_mayor adj beijing-xinjiang i.year ,  r
 est store m2
 cnsreg lntotal connected_mayor adj lngdp1 lngdp2 beijing-xinjiang i.year , c(1 ) r
 est store m3
 cnsreg lntotal connected_mayor adj lngdp1 lngdp2 lntrade1 lntrade2 beijing-xinjiang i.year , c(1-2) r
 est store m4
 cnsreg lntotal connected_mayor adj lngdp1 lngdp2 lntrade1 lntrade2 guoqibizhong1 guoqibizhong2 beijing-xinjiang i.year , c(1-3) r
 est store m5
 cnsreg lntotal connected_mayor adj lngdp1 lngdp2 lntrade1 lntrade2 guoqibizhong1 guoqibizhong2 urban1 urban2 beijing-xinjiang i.year , c(1-4) r
 est store m6
 
 outreg2 [m1 m2 m3 m4 m5 m6    ] using $root\Tables\基准回归结果.doc, replace
 shellout  $root\Tables\基准回归结果.doc 
 
 //仅有宁夏和云南两省不是省长的籍贯所在地，出产省长最多的省份是浙江、江苏和山东省。
  //----------2、稳健性检验-------------------------
 clear
 use WorkingData.dta
 
  constraint 1 lngdp1 = lngdp2
 constraint 2 lntrade1 = lntrade2
 constraint 3 guoqibizhong1 = guoqibizhong2
 constraint 4 urban1 = urban2
 
    cnsreg lntotal connected_sec adj lngdp1 lngdp2 lntrade1 lntrade2 guoqibizhong1 guoqibizhong2 urban1 urban2      beijing-xinjiang i.year  , c(1-5) r
	est store m1
 gen zhixiashi= (strmatch(cp_prov,"*北京*")==1 | strmatch(cp_prov,"*天津*")==1 |strmatch(cp_prov,"*上海*")==1 |strmatch(cp_prov,"*重庆*")==1 )
  cnsreg lntotal connected_mayor adj lngdp1 lngdp2 lntrade1 lntrade2 guoqibizhong1 guoqibizhong2 urban1 urban2      beijing-xinjiang i.year if zhixiashi==0 , c(1-5) r
 est store m2
   cnsreg lntotal connected_mayor adj lngdp1 lngdp2 lntrade1 lntrade2 guoqibizhong1 guoqibizhong2 urban1 urban2           beijing-xinjiang i.year if (strmatch(cp_prov,"*浙江*") !=1 & strmatch(cp_prov,"*江苏*") !=1 & strmatch(cp_prov,"*山东*") !=1), c(1-5) r
 est store m3
drop _merge
merge 1:1 cp_prov year using 煤炭.dta 
gen lngoods= ln(total-total_mt)
cnsreg lngoods connected_mayor adj lngdp1 lngdp2 lntrade1 lntrade2 guoqibizhong1 guoqibizhong2 urban1 urban2 beijing-xinjiang i.year , c(1-5) r
 est store m4
 gen tks_prov= (strmatch(cp_prov,"*河北*")==1 | strmatch(cp_prov,"*辽宁*")==1 |strmatch(cp_prov,"*四川*") ==1)
 cnsreg lntotal connected_mayor adj lngdp1 lngdp2 lntrade1 lntrade2 guoqibizhong1 guoqibizhong2 urban1 urban2           beijing-xinjiang i.year if tks_prov==0, c(1-5) r
 est store m5
  outreg2 [m1 m2 m3 m4  m5  ] using  $root\Tables\稳健性检验.doc, replace
 shellout  $root\Tables\稳健性检验.doc 


 //-----------3、对流入流出的影响-------------------------
 use WorkingData.dta,clear
 
 
 reg lnvolume12 connected_mayor i.id_prov1 i.id_prov2 i.year , r
 est store m1
 reg lnvolume12 connected_mayor adj lngdp1 lngdp2 lntrade1 lntrade2 guoqibizhong1 guoqibizhong2 urban1 urban2          i.id_prov1 i.id_prov2 i.year , r
 est store m2
 reg lnvolume12 connected_mayor adj lngdp1 lngdp2 lntrade1 lntrade2 guoqibizhong1 guoqibizhong2 urban1 urban2          i.id_prov1#i.year  i.id_prov2#i.year , r
 est store m3
  reg lnvolume21 connected_mayor i.id_prov1 i.id_prov2 i.year , r
 est store m4
 reg lnvolume21 connected_mayor adj lngdp1 lngdp2 lntrade1 lntrade2 guoqibizhong1 guoqibizhong2 urban1 urban2           i.id_prov1 i.id_prov2 i.year , r
 est store m5
 reg lnvolume21 connected_mayor adj lngdp1 lngdp2 lntrade1 lntrade2 guoqibizhong1 guoqibizhong2 urban1 urban2            i.id_prov1#i.year  i.id_prov2#i.year , r
 est store m6
 outreg2 [m1 m2 m3 m4 m5 m6] using  $root\Tables\流入流出.doc, replace
 shellout  $root\Tables\流入流出.doc 
   
  //*******4、煤炭*************
  clear
 use WorkingData.dta
 drop _merge
 merge 1:1 cp_prov year using 煤炭.dta 
 replace total_mt =0 if total_mt==.
 replace volume12_mt=0 if volume12==.
 replace volume21_mt=0 if volume21==.
 gen lntotal_mt= ln(total_mt+1)
 gen lnvolume12_mt= ln(volume12_mt+1)
 gen lnvolume21_mt= ln(volume21_mt+1)
 gen lngoods= ln(total-total_mt+1)
 gen lngoods_12= ln(volume12-volume12_mt+1)
 gen lngoods_21= ln(volume21-volume21_mt+1)
 
 
 reg lngoods_12 connected_mayor adj lngdp1 lngdp2 lntrade1 lntrade2 guoqibizhong1 guoqibizhong2 urban1 urban2 i.id_prov1 i.id_prov2 i.year , r
est store m1
 reg lngoods_21 connected_mayor adj lngdp1 lngdp2 lntrade1 lntrade2 guoqibizhong1 guoqibizhong2 urban1 urban2 i.id_prov1 i.id_prov2 i.year  , r
est store m2
 reg lnvolume12_mt connected_mayor adj lngdp1 lngdp2 lntrade1 lntrade2 guoqibizhong1 guoqibizhong2 urban1 urban2 i.id_prov1 i.id_prov2 i.year , r
est store m3
 reg lnvolume21_mt connected_mayor adj lngdp1 lngdp2 lntrade1 lntrade2 guoqibizhong1 guoqibizhong2 urban1 urban2 i.id_prov1 i.id_prov2 i.year  , r
est store m4
outreg2 [m1 m2 m3 m4 ] using  $root\Tables\煤炭.doc, replace
shellout  $root\Tables\煤炭.doc 
 
 //*******5、省生产结构差异*************
 use WorkingData.dta, clear
 
   constraint 1 lngdp1 = lngdp2
 constraint 2 lntrade1 = lntrade2
 constraint 3 guoqibizhong1 = guoqibizhong2
 constraint 4 urban1 = urban2
 
 gen con_chanye=connected_mayor*chanye
 cnsreg lntotal connected_mayor chanye adj lngdp1 lngdp2 lntrade1 lntrade2 guoqibizhong1 guoqibizhong2 urban1 urban2           beijing-xinjiang i.year ,c(1-4) r
 est store m1
 cnsreg lntotal connected_mayor chanye con_chanye adj lngdp1 lngdp2 lntrade1 lntrade2 guoqibizhong1 guoqibizhong2 urban1 urban2 beijing-xinjiang i.year ,c(1-4) r
 est store m2
 reg lnvolume12 connected_mayor chanye adj lngdp1 lngdp2 lntrade1 lntrade2 guoqibizhong1 guoqibizhong2 urban1 urban2            i.id_prov1#i.year  i.id_prov2#i.year, r
est store m3

 reg lnvolume12 connected_mayor chanye  con_chanye adj lngdp1 lngdp2 lntrade1 lntrade2 guoqibizhong1 guoqibizhong2 urban1 urban2 i.id_prov1#i.year  i.id_prov2#i.year , r
est store m4
 reg lnvolume21 connected_mayor chanye adj lngdp1 lngdp2 lntrade1 lntrade2 guoqibizhong1 guoqibizhong2 urban1 urban2 i.id_prov1#i.year  i.id_prov2#i.year , r
est store m5
 reg lnvolume21 connected_mayor chanye con_chanye adj lngdp1 lngdp2 lntrade1 lntrade2 guoqibizhong1 guoqibizhong2 urban1 urban2 i.id_prov1#i.year  i.id_prov2#i.year , r
est store m6
 outreg2 [m1 m2 m3 m4 m5 m6 ] using  $root\Tables\生产结构.doc, replace
 shellout  $root\Tables\生产结构.doc 
 
 //*******6、年龄天花板的影响*************
 use WorkingData.dta, clear
 gen jinsheng_age= 2002- birthyear_mayor if year<=2002
 replace jinsheng_age= 2007- birthyear_mayor if year>2002 & year<=2007 
  replace jinsheng_age= 2012- birthyear_mayor if year>2007 & year<=2012 
  replace jinsheng_age= 2017- birthyear_mayor if year>2012 & year<=2017 
  
    constraint 1 lngdp1 = lngdp2
 constraint 2 lntrade1 = lntrade2
 constraint 3 guoqibizhong1 = guoqibizhong2
 constraint 4 urban1 = urban2
  
 gen jinshengnianling= (jinsheng_age<=65)

 gen x_nianling = jinshengnianling*connected_mayor
 cnsreg lntotal connected_mayor jinshengnianlin adj lngdp1 lngdp2 lntrade1 lntrade2 guoqibizhong1 guoqibizhong2 urban1 urban2          beijing-xinjiang i.year ,c(1-4) r
 est store m1
 cnsreg lntotal connected_mayor jinshengnianlin x_nianling adj lngdp1 lngdp2 lntrade1 lntrade2 guoqibizhong1 guoqibizhong2 urban1 urban2          beijing-xinjiang i.year ,c(1-4) r
 est store m2
 reg lnvolume12 connected_mayor jinshengnianlin adj lngdp1 lngdp2 lntrade1 lntrade2 guoqibizhong1 guoqibizhong2 urban1 urban2             i.id_prov1#i.year  i.id_prov2#i.year, r
est store m3
 reg lnvolume12 connected_mayor jinshengnianlin x_nianling adj lngdp1 lngdp2 lntrade1 lntrade2 guoqibizhong1 guoqibizhong2 urban1 urban2             i.id_prov1#i.year  i.id_prov2#i.year , r
est store m4
 reg lnvolume21 connected_mayor jinshengnianlin adj lngdp1 lngdp2 lntrade1 lntrade2 guoqibizhong1 guoqibizhong2 urban1 urban2         i.id_prov1#i.year  i.id_prov2#i.year, r
est store m5
 reg lnvolume21 connected_mayor jinshengnianlin x_nianling adj lngdp1 lngdp2 lntrade1 lntrade2 guoqibizhong1 guoqibizhong2 urban1 urban2         i.id_prov1#i.year  i.id_prov2#i.year, r
est store m6
 outreg2 [m1 m2 m3 m4 m5 m6 ] using  $root\Tables\年龄.doc, replace
 shellout  $root\Tables\年龄.doc 
 